// token管理
const TokenKey = 'Admin-Token'
const RememberKey = 'Remember-Login'

export function getToken(): string | undefined {
  return uni.getStorageSync(TokenKey)
}

export function setToken(token: string): void {
  uni.setStorageSync(TokenKey, token)
}

export function removeToken(): void {
  uni.removeStorageSync(TokenKey)
}

// 记住密码相关
export interface RememberData {
  username: string;
  password: string;
  rememberMe: boolean;
  timestamp: number;
}

export function setRememberData(data: RememberData): void {
  uni.setStorageSync(RememberKey, data)
}

export function getRememberData(): RememberData | null {
  const data = uni.getStorageSync(RememberKey)
  if (!data) return null
  
  // 检查是否超过30天
  const now = Date.now()
  const thirtyDays = 30 * 24 * 60 * 60 * 1000 // 30天的毫秒数
  
  if (now - data.timestamp > thirtyDays) {
    // 超过30天，清除数据
    removeRememberData()
    return null
  }
  
  return data
}

export function removeRememberData(): void {
  uni.removeStorageSync(RememberKey)
} 